/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package estates.model;

import estates.util.Identifiable;
import java.util.*;
import java.io.Serializable;

public class User extends Identifiable implements Serializable, Comparable<User> {

  private Long id;

  private String login;
  private String pesel;
  private String password;
  private String name;
  private String street;
  private String houseNr;
  private String postCode;
  private String city;
  private String mail;
  private String phone;
  private String nip;
  private String regon;
  private String additionalInf;
  private UserTypes userType;


    public User() {
		
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	private List<Estate> mestates = new ArrayList<Estate>();

    public List<Estate> getMestates() {
        return mestates;
    }

    public void setMestates(List<Estate> mestates) {
        this.mestates = mestates;
    }

  private List<Estate> estates = new ArrayList<Estate>();
  
  private List<Comment> comments = new ArrayList<Comment>();

  private List<Estate> obserwowane = new ArrayList<Estate>();


    public List<Estate> getObserwowane() {
        return obserwowane;
    }

    public void setObserwowane(List<Estate> obserwowane) {
        this.obserwowane = obserwowane;
    }

  public List<Comment> getComments() {
	return comments;
  }

  public void setComments(List<Comment> comments) {
    this.comments= comments;
  }

  public List<Estate> getEstates() {
    return estates;
  }

  public void setEstates(List<Estate> estates) {
    this.estates = estates;
  }

  public String getLogin() {
    return login;
  }

  public void setLogin(String log) {
    login = log;
  }

  public String getPassword() {
    return password;
  }

  public void setPassword(String pass) {
    password = pass;
  }

  public String getName() {
    return name;
  }

  public void setName(String nam) {
    name = nam;
  }

  public String getStreet() {
    return street;
  }

  public void setStreet(String str) {
    street = str;
  }

  public String getHouseNr() {
    return houseNr;
  }

  public void setHouseNr(String house) {
    houseNr = house;
  }

  public String getPostCode() {
    return postCode;
  }

  public void setPostCode(String postC) {
    postCode = postC;
  }

  public String getCity() {
    return city;
  }

  public void setCity(String c) {
    city = c;
  }

  public String getMail() {
    return mail;
  }

  public void setMail(String m) {
    mail = m;
  }

  public String getPhone() {
    return phone;
  }

  public void setPhone(String ph) {
    phone = ph;
  }

  public String getNIP() {
    return nip;
  }

  public void setNIP(String n) {
    nip = n;
  }

  public String getPesel() {
    if (this.userType.equals(UserTypes.company)) {
      return null;
    } else {
      return pesel;
    }
  }

  public void setPesel(String Pesel) {
    if (this.userType.equals(UserTypes.company)) {
      pesel = null;
    } else {
      pesel = Pesel;
    }
  }

  public String getRegon() {
    if (this.userType.equals(UserTypes.company)) {
      return regon;
    } else {
      return null;
    }
  }

  public void setRegon(String r) {
    if (this.userType.equals(UserTypes.company)) {
      regon = r;
    } else {
      regon = null;
    }
  }

  public String getAdditionalInf() {
    return additionalInf;
  }

  public void setAdditionalInf(String ad) {
    additionalInf = ad;
  }

  public UserTypes getUserType() {
    return userType;
  }

  public void setUserTypes(int a) {
    if (a == 0) {
      userType = userType.normal;
    } else if (a == 1) {
      userType = userType.company;
    } else if (a == 2) {
      userType = userType.worker;
    } else if (a == 3) {
      userType = userType.agent;
    } else if (a == 4) {
      userType = userType.admin;
    } else {
      userType = userType.normal;
    }
  }

  public int compareTo(User nowy) {
    if (Integer.parseInt(this.nip) < Integer.parseInt(nowy.nip)) {
      return -1;
    } else if (Integer.parseInt(this.nip) > Integer.parseInt(nowy.nip)) {
      return 1;
    } else {
      return 0;
    }
  }

  @Override
  public boolean equals(Object o) {
    if (!(o instanceof User)) {
      return false;
    }
    User nowy = (User) o;
    return this.nip.equals(nowy.nip);
  }

  @Override
  public int hashCode() {
    int hash = 3;
    hash = 53 * hash + (this.nip != null ? this.nip.hashCode() : 0);
    return hash;
  }

  @Override
  public String toString() {
    String pom;
    pom = "login=" + login +
            "&password=" + password +
            "&name=" + name +
            "&street=" + street + "&houseNr=" + houseNr +
            "&postCode=" + postCode +
            "&city=" + city +
            "&mail=" + mail + "&phone=" + phone +
            "&nip=" + nip;

    if (this.userType.equals(UserTypes.company)) {
      pom += "&regon=" + regon;
    } else {
      pom += "&pesel=" + pesel;
    }

    pom += "&additionalInf=" + additionalInf;

    pom += "&userType=";
    if (userType == userType.normal) {
      pom += "zwykły użytkownik";
    } else if (userType == userType.company) {
      pom += "firma";
    } else if (userType == userType.admin) {
      pom += "administrator";
    } else if (userType == userType.agent) {
      pom += "agent nieruchomości";
    } else if (userType == userType.worker) {
      pom += "pracownik";
    } else {
      pom += "undefinedUser";
    }
    return pom;
  }

  public void addComment(Comment comment) {
	  comments.add(comment);
  }
}
